/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.zeos.util;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

/**
 *
 * @author virtual
 */
public class ImagePane extends JPanel {

    private byte[] image = null;

    public ImagePane() {

    }

    @Override
    protected void paintComponent(Graphics g) {
        g.clearRect(0, 0, this.getWidth(), this.getHeight());
        if (this.image == null) {
            g.setColor(Color.WHITE);
            g.drawRect(0, 0, this.getWidth(), this.getHeight());
        } else {
            Image img = new ImageIcon(this.image).getImage();
            g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), null);
        }

    }

    public byte[] getImage() {
        return image;
    }

    public void setImage(byte[] image) {
        this.image = image;
        this.repaint();
        paintComponent(this.getGraphics());
    }

}
